﻿package  {
	import flash.display.MovieClip;
	import flash.display.Graphics;
	//import com.cartogrammar.drawing.CubicBezier;
	import flash.geom.Point;
	import flash.events.MouseEvent;
	import flash.ui.Mouse;
	import fl.transitions.Tween;
	import fl.motion.easing.Elastic;
	import fl.motion.easing.Cubic;
	
	public class Main extends MovieClip {
		
		var art:MovieClip = new MovieClip();
		var g:Graphics = art.graphics;
		
		var is_painting:Boolean = false;
		var lineSize = 6;

		public function Main() {
			// constructor code
			
			stage.addChild(art);
			//art.x = stage.stageWidth * 0.5;
            //art.y = stage.stageHeight * 0.5
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN, startPaint);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, whilePaint);
			stage.addEventListener(MouseEvent.MOUSE_UP, stopPaint);
			stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoom);
			
			var points:Array = new Array(new Point(47,109),new Point(500,200),new Point(177,89),new Point(113,120),new Point(220,150),new Point(247,102),new Point(307,104),new Point(316,153),new Point(79,172),new Point(292,171));
			
			g.lineStyle(lineSize, 0x000000, 1);
			
			//CubicBezier.curveThroughPoints(g, points,.2,1, true);
			
		}
		
		private function startPaint(e:MouseEvent) {
			is_painting = true;
			g.moveTo(art.mouseX, art.mouseY);
		}
		
		private function whilePaint(e:MouseEvent) {
			if (is_painting) {
				art.mouseX
				g.lineTo(art.mouseX, art.mouseY);
			}
		}
		
		private function stopPaint(e:MouseEvent) {
			is_painting = false;
		}
		
		private function zoom(e:MouseEvent) {
			var mod:Number = 3;
			
			var curx = e.localX;
			var cury = e.localY;
			
			var newScale = art.scaleX + e.delta / mod;
			
            //art.scaleX += e.delta / mod;
           // art.scaleY += e.delta / mod;
			if ((newScale > 0 && e.delta<0) || e.delta>0) {
				// new Tween(null, "", Elastic.easeOut, square.scaleX, 4, 1, true);
				new Tween(art, "scaleX", Cubic.easeOut, art.scaleX, newScale, 1, true);
				new Tween(art, "scaleY", Cubic.easeOut, art.scaleX, newScale, 1, true);
				
				//art.x = ((2 * mouseX) - (2 * (e.localX * art.scaleX))) / 2;
				
				g.lineStyle(lineSize / newScale, 0x000000, 1);
			}
		}

	}
	
}
